import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sgy_flutter/page/adjust_zero/adjust_zero_success/view.dart';
import 'package:sgy_flutter/widget/app_bar_x.dart';
import 'package:sgy_flutter/widget/sgy_scaffold.dart';

import 'logic.dart';

class AdjustZeroPage extends StatefulWidget {
  const AdjustZeroPage({Key? key}) : super(key: key);

  @override
  State<AdjustZeroPage> createState() => _AdjustZeroPageState();
}

class _AdjustZeroPageState extends State<AdjustZeroPage> {
  final logic = Get.put(AdjustZeroLogic());

  @override
  Widget build(BuildContext context) {
    return SgyScaffold(title: '零点校准'.tr, child: Column(
      children: [
        Expanded(
          child: Center(
            child: Obx(
                  () => Visibility(
                  visible: logic.image.isNotEmpty,
                  child: Image.asset(
                    logic.image.value,
                    width: 266,
                    height: 340,
                  )),
            ),
          ),
        ),
        Obx(() => Text(
          logic.alert.value,
          style: Get.textTheme.bodySmall,
        )).marginSymmetric(horizontal: 16),
        Container(
          margin: EdgeInsets.symmetric(vertical: 16, horizontal: 16),
          width: double.infinity,
          child: Obx(() => FilledButton(
              onPressed: logic.adjusting.isTrue
                  ? null
                  : () async{
                final result = await logic.adjustZero();
                if (result){
                  Get.off(()=> AdjustZeroSuccessPage());
                }
                Get.off(()=> AdjustZeroSuccessPage());

              },
              child: Text("开始校准".tr))),
        ),
      ],
    ),);
  }

  @override
  void dispose() {
    Get.delete<AdjustZeroLogic>();
    super.dispose();
  }
}
